/**
 * Class: Dot2D
 *
 * Purpose: 
 *
 * Created: Jan 27, 2010 @ 9:37:10 AM
 * @author Ken Scott
 */
package org.openfantasia.ps.shape;

import org.openfantasia.ps.particle.Particle;
import org.openfantasia.ui.PFrame;
import org.openfantasia.util.math.DPoint3;
import org.openfantasia.util.math.PMath;

public class Rose extends Shape {

	public static final String PHI = "phi";

	public static final String THETA = "theta";

	protected double phi;

	protected double theta;


	public Rose(PFrame frame) {
		super(frame);
	}


	public Rose(PFrame frame, DPoint3 size) {
		super(frame, size);
	}


	public double getPhi() {
		return phi;
	}


	public double getPhi(Particle particle) {
		return (Double) getBehaviorValue(PHI, particle, getTime(), getPhi());
	}


	public void setPhi(double phi) {
		this.phi = phi;
	}


	public double getTheta() {
		return theta;
	}


	public double getTheta(Particle particle) {
		return (Double) getBehaviorValue(THETA, particle, getTime(), getTheta());
	}


	public void setTheta(double theta) {
		this.theta = theta;
	}


	public void drawShape(Particle particle) {
		DPoint3 prev = DPoint3.INVALID;
		DPoint3 next = new DPoint3();
		double pPhi = getPhi(particle);
		double pTheta = getTheta(particle);

		frame.beginShape(PFrame.LINES);

		double detail = getDetail();
		for (double i = 0; i < detail; i++) {
			double fracPi = PMath.TWO_PI * i / detail;

			double phiAngle = pPhi * fracPi;
			double cosPhi = PMath.cos(phiAngle);
			double ampX = cosPhi;
			double ampY = cosPhi;
			double ampZ = cosPhi;

			double thetaAngle = pTheta * fracPi;
			double tx = PMath.sin(thetaAngle);
			double ty = PMath.cos(thetaAngle);
			double px = ampX * tx;
			double py = ampY * ty;
			double pz = 0;
			next.set(px, py, pz);
			if (prev == DPoint3.INVALID) {
				frame.point(next);
			}
			else {
				frame.line(prev, next);
			}
			prev.set(next);
		}

		frame.endShape();
	}

}